#include <iostream>
#include <set>
#include <ctime>
#include <map>
#include <limits>
#include <vector>
#include <list>
#include <stack>
#include <math.h>

using namespace std;
double sum;
int pips = 1;

vector< pair< int, int > > getTree( int n, vector< vector< double > >* g ) {
	vector<  pair< int, int > > path;
	vector< bool > used( n, false );
	vector< double > min_e( n, std::numeric_limits< double >::infinity() );
	vector< int > sel_e( n, -1 );
	min_e[0] = 0;
	for( int i = 0; i < n; ++i ) {
		int v = -1;
		for( int j = 0; j < n; ++j )
			if( !used[j] && ( v == -1 || min_e[j] < min_e[v] ) )
				v = j;
		if( min_e[v] == std::numeric_limits< double >::infinity() ) {
			//cout << "NO";
			pips = -1;
			return path;
		}
 
		used[v] = true;
		if( sel_e[v] != -1 )  {
			//cout << v << " " << sel_e[v] << min_e[v] << endl;
			path.push_back( make_pair( v, sel_e[v] ) );
			sum += ( *g )[v][sel_e[v]];

		}
 
		for( int to = 0; to < n; ++to )
			if( ( *g )[v][to] < min_e[to] ) {
				min_e[to] = ( *g )[v][to];
				sel_e[to] = v;
			}
	}
	return path;
};


int main() {
	sum = 0;
	int n;
	freopen( "1.txt", "r", stdin );
    cin >> n;
	vector< vector< double > > g;
	for( int i = 0; i < n; ++i ) {
		vector< double > kk( n, std::numeric_limits< double >::infinity() );
		g.push_back( kk );
	}
    while( true ) {
        int x, y;
		double cost;
        cin >> x >> y >> cost;
        if( y != x ) {
			g[x][y] = cost;
			g[y][x] = cost;
		}
        if( x == 0 && y == 0 )
            break;
    }	
	vector< pair< int, int > > path = getTree( n, &g );
	vector< vector< pair< int, int > > > msts;
	vector< int > sums;
	int num = -1;
	if( pips == -1 ) {
		freopen( "2.txt", "w", stdout );
		cout << "NO";
		return 0;
	}
	pips = 1;
	int min;
	for( int i = 0; i < path.size(); ++i ) {
		sum = 0;
		int fir = path[i].first;
		int sec = path[i].second;
		double cos = g[fir][sec];
		g[fir][sec] = std::numeric_limits< double >::infinity();
		g[sec][fir] = std::numeric_limits< double >::infinity();
		path = getTree( n, &g );
		if( pips != -1 ) {
			if( msts.size() == 0 ) {
				min = sum;
				msts.push_back( path );
				num++;
				sums.push_back( sum );
			}
			else {
				if( sum < min ) {
					min = sum;
					msts.push_back( path );
					num++;
					sums.push_back( sum );
				}
			}
		}
		else
			pips = 1;
		g[fir][sec] = cos;
		g[sec][fir] = cos;
	}
	
	freopen( "2.txt", "w", stdout );
	if( num == -1 ) 
		cout << "NO";
	else {
		for( int i = 0; i < msts[num].size(); ++i ) {
			cout << msts[num][i].first << " " << msts[num][i].second << " " << g[ msts[num][i].second ][ msts[num][i].first ] << endl;
		}
	}
	return 0;
};